package Text6;

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    static int N = 110;
    static boolean[][] f = new boolean[N][N];
    static char[] a = new char[N];
    static char[] b = new char[N];
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s1 = in.next();
        a = s1.toCharArray();
        String s2 = in.next();
        b = s2.toCharArray();
        f[0][0] = true;
        int k = 0;
        while (true) {
            if (a[k++] == '*') {
                f[0][k] = true;
            } else {
                break;
            }
        }
        for (int j = 1; j <= s2.length(); j++) {
            for (int i = 1; i <= s1.length(); i++) {
                if (a[i - 1] == '*') {
                    f[j][i] = f[j - 1][i - 1] || f[j][i-1];
                } else if (a[i - 1] == '?') {
                    f[j][i] = f[j-1][i - 1];
                } else if (lowch(a[i - 1]) == lowch(b[j - 1])) {
                    f[j][i] = f[j - 1][i - 1];
                } else {
                    f[j][i] = false;
                }
            }
        }

        System.out.println(f[s2.length()][s1.length()]);
    }
    private static int lowch(char ch) {
        if (ch >= 'A' && ch <= 'Z') {
            return ch + 32;
        }
        return ch;
    }
}